package com.aaa.service.impl;

import com.aaa.common.domain.ContractInfo;
import com.aaa.common.query.ConditionalQuery;
import com.aaa.common.query.PageQuery;
import com.aaa.common.result.Result;
import com.aaa.mapper.PublicAssetsContractInfoMapper;
import com.aaa.service.PublicAssetsContractInfoService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Created with IntelliJ IDEA.
 *
 * @Auther: 宋文森
 * @Date: 2021/02/03/13:46
 * @Description: 公有资产出租合同服务实现类
 */
@Service
public class PublicAssetsContractServiceImpl implements PublicAssetsContractInfoService {
    @Autowired
    PublicAssetsContractInfoMapper mapper;


    /**
     * 查询所有的合同信息（分页）
     * PageHelper 分页插件
     * @param pageQuery
     * @return Result
     */
    public Result listAll(PageQuery pageQuery) {
        Page<ContractInfo> contractInfoPage = new Page<>(pageQuery.getCurrentPage(),pageQuery.getPageCount());
        Page<ContractInfo> contractInfos = mapper.listContract(contractInfoPage);
        if (contractInfos!=null){
            return  Result.success(contractInfos);
        }
        return  Result.error("公有资产出租合同查询失败");
    }


    /**
     * 条件查询
     * @param conditionalQuery
     * @return
     */
    public Result conditionalQuery(ConditionalQuery conditionalQuery) {
        Page<ContractInfo> contractInfoPage = new Page<>(conditionalQuery.getCurrentPage(),conditionalQuery.getPageCount());
        Page<ContractInfo> contractInfos = mapper.conditionalQuery(contractInfoPage,conditionalQuery.getContractId(),conditionalQuery.getAssetId(),conditionalQuery.getLessee(),conditionalQuery.getCompanyName(),conditionalQuery.getContractStatusId());
        if (contractInfos!=null){
            return Result.success(contractInfos);
        }
        return Result.error("其他资产出租合同信息条件查询失败");
    }

}
